
# to start a maya session import pymel
import pymel.core as pm


import maya.OpenMaya as OpenMaya
import maya.OpenMayaRender as OpenMayaRender
import maya.OpenMayaUI as OpenMayaUI

# find the persp

dagIt = OpenMaya.MItDag()

perspShape = OpenMaya.MObject()
perspShapeDagPath = OpenMaya.MDagPath()

while( not dagIt.isDone() ):
    
    if dagIt.partialPathName() == 'perspShape':
        #print 'found persp';
        #perspShapeDagPath = dagIt.getPath( perspShapeDagPath )
        dagIt.getPath( perspShapeDagPath )
        break
    dagIt.next()
    
cameraMatrix = OpenMaya.MFnCamera( perspShapeDagPath ).transformationMatrix()

#print cameraMatrix

glFT = OpenMayaRender.MHardwareRenderer.theRenderer().glFunctionTable()


glFT.glPushMatrix()

su = OpenMaya.MScriptUtil()

modelView = ( cameraMatrix[0],  cameraMatrix[1],  cameraMatrix[2],  cameraMatrix[3], \
              cameraMatrix[4],  cameraMatrix[5],  cameraMatrix[6],  cameraMatrix[3], \
              cameraMatrix[8],  cameraMatrix[9],  cameraMatrix[10], cameraMatrix[11], \
              cameraMatrix[12], cameraMatrix[13], cameraMatrix[14], cameraMatrix[15] )


su.createFromList( modelView, 16 )
suPointer = su.asDoublePtr()
glFT.glGetDoublev( OpenMayaRender.MGL_MODELVIEW, suPointer)

glFT.glPushMatrix()
glFT.glLoadMatrixd( suPointer )

glFT.glBegin()



glFT.glEnd()
glFT.glPopMatrix()